'use strict';

exports.main = async (event, context) => {
  const { name, contact, content } = event;

  // 校验数据
  if (!name || !contact || !content) {
    return {
      code: 400,
      message: '缺少必要参数',
    };
  }

  try {
    // 插入数据到 feedback 集合
    const res = await uniCloud.database().collection('feedback').add({
      name,
      contact,
      content,
      createTime: Date.now(),
    });

    return {
      code: 200,
      message: '反馈提交成功',
      data: res,
    };
  } catch (err) {
    return {
      code: 500,
      message: '反馈提交失败',
      error: err.message,
    };
  }
}; 